home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7257 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: pegasus.montclair.edu!harmon
  2. From: harmon@pegasus.montclair.edu (Derek Harmon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fwrite help?
  5. Date: 12 Feb 1996 17:52:03 -0500
  6. Organization: Montclair State University
  7. Message-ID: <harmon.824165113@pegasus.montclair.edu>
  8. References: <4fmaig$7of@news.global1.net>
  9. NNTP-Posting-Host: pegasus.montclair.edu
  10. X-Newsreader: NN version 6.5.0 #68 (NOV)
  11.  
  12. youngrc@global1.net writes:
  13. >What would the syntax for fwrite be to output 8 characters of 
  14. >char line[10] to a file?  K&R doesn't write much about it. Thanks
  15. >for the help.
  16.  
  17. size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream); is the
  18. prototype I have.  You can use line to devolve into a pointer towards the
  19. first element in line, sizeof(char) for size insures compatibility on machines
  20. where a character is more than one byte, and since you want 8 characters, set
  21. n to 8.
  22.  
  23. : fwrite( line, sizeof(char), 8, fp);
  24.  
  25.    Of course, when they are contiguous in an array, and you know the sizeof a
  26. char is 1 byte, it's much more efficient to say you want to write an 8-byte
  27. block of memory once, instead of a 1-byte block of memory eight times.
  28.  
  29.                                                     -- Stone
  30. --
  31. # Derek Harmon (aka Stonelight)    harmon@pegasus.montclair.edu
  32. # - Computer Science Undergrad, Montclair State University, NJ
  33. # - My views are my own, nobody else is this creative.  3;)>
  34. ... On a clear disk, you can seek forever.
  35.